<?php

class EnquiryController extends CController {

    public function filters() {
        return array(
            'ajaxOnly',
            'accessControl',
        );
    }
    public function actionIndex() {
        echo "Access denied.";
    }
    public function actionCheckDO(){


/*      
        $criteria = new CDbCriteria();
        $criteria->condition = 'upper(replace(`ref_no`," ",""))=:ref_no';
        $criteria->params = array(':ref_no'=>str_replace(' ','',strtoupper($_GET['q'])));
        $model = cargo::model()->findAll($criteria);
        echo 'qwdqwd';*/
    }
    public function actionRegisteredRef() {

        $criteria = new CDbCriteria;
    }
    public function actionPacking_List_Package_Form() {
        $model = new packing_list_packages;
        echo $this->renderPartial('../packing_list/_packingform', array('model'=>$model), true);
    }
    public function actionOrigin() {
        $import = new import;
        $returnVal = array();
        $criteria = new CDbCriteria;
        $criteria->condition = "origin like :origin";
        $criteria->order = "origin asc";
        $criteria->group = "origin";
        $criteria->limit = 10;
        $criteria->params = array(":origin"=>$_GET['q'].'%');
        $models = $import->findAll($criteria);
        foreach($models as $model) {
            $returnVal[] = $model->origin;
        }
        echo join($returnVal,'\n');
    }
    public function actionJobNo() {
        $subcert = new import;
        $criteria = new CDbCriteria;
        $criteria->condition = "jobno like :jobno";
        $criteria->order = "eta asc";
        $criteria->limit = 10;
        $criteria->params = array(":jobno"=>$_GET['q']);
        $models = $subcert->find($criteria);
        if($models== NULL)
            $returnVal[] = "Add this permit|0|".$_GET['q'];
        else{
            echo $models->jobno ."|" . $models->id;
            return;
        }
        $criteria->params = array(":jobno"=>$_GET['q']."%");
        $models = $subcert->findAll($criteria);
        foreach($models as $model) {
            $returnVal[] = $model->jobno ."|". $model->id;
        }
        echo join($returnVal,"\n");
    }
    public function filterNewRecord($filterChain) {
        $name = $_GET['q'];
        if(strpos($name,'<<')!==false && strrpos($name,'>>')!==false)
            return false;
        else
            $filterChain->run();
    }
    public function actionExportPermit() {
        $returnVal = array();
        $subcert = new subcert;
        $criteria = new CDbCriteria;
        $criteria->condition = "out_permit like :out_permit";
        $criteria->order = "out_permit asc";
        $criteria->limit = 10;
        $criteria->params = array(":out_permit"=>$_GET['q']);
        $models = $subcert->find($criteria);
        if($models== NULL)
            $returnVal[] = "Add this permit|0|".$_GET['q'];
        else{
            echo $models->out_permit ."|" . $models->id;
            return;
        }
        $criteria->params = array(":out_permit"=>$_GET['q']."%");
        $models = $subcert->findAll($criteria);
        foreach($models as $model) {
            $returnVal[] = $model->out_permit ."|". $model->id;
        }
        echo join($returnVal,"\n");
    }
    public function actionGetRef(){
        $contact = new cargo_details;
        $model = $contact->findByPk($_GET['cid']);
        if($model == NULL)
            echo "Error";
        else
            echo $model->ref_no;
    }
    public function actionContactName() {
        $contact = new company;
        $criteria = new CDbCriteria;
        $returnVal=array();
        $criteria->condition = "cname like :cname";
        $criteria->order = "cname asc";
        $criteria->limit = 10;
        $criteria->params = array(":cname"=>$_GET['q']);
        $models = $contact->find($criteria);
        if( $models== NULL)
            $returnVal[] = "Add this contact|0|".$_GET['q'];
        else{
            echo $models->cname ."|" . $model->id;
            return;
        }
        $criteria->params = array(":cname"=>$_GET['q']."%");
        $models = $contact->findAll($criteria);
        foreach($models as $model) {
            $returnVal[] = $model->cname ."|". $model->id;
        }
        $criteria->params = array(":cname"=>"%".$_GET['q']."%");
        $models = $contact->findAll($criteria);
        foreach($models as $model) {
            $item = $model->cname ."|". $model->id;
            if(!in_array($item,$returnVal))
                $returnVal[] = $item;
        }
        echo join($returnVal,"\n");

    }
// -----------------------------------------------------------
// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}